// <copyright file="CustomCollection.cs" company="company"> 
// (C) 2010 . All rights reserved
// </copyright>
// <author>Lukasz Bartczak</author>

namespace WcfService1
{
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Runtime.Serialization;

    /// <summary>
    /// Kolekcja sparametryzowana
    /// </summary>
    /// <typeparam name="T">Typ kolekcji.</typeparam>
    [Serializable]
    [CollectionDataContract]
    public class CustomCollection<T> : IEnumerable<T>
    {
        /// <summary>
        /// List of type T data.
        /// </summary>
       private List<T> collection = new List<T>();

       /// <summary>
       /// Gets or sets the collection.
       /// </summary>
       /// <value>The collection.</value>
        public List<T> Collection
        {
            get { return this.collection; }
            set { this.collection = value; }
        }

        /// <summary>
        /// Gets a value indicating whether this instance is read only.
        /// </summary>
        /// <value>
        ///    <c>true</c> if this instance is read only; otherwise, <c>false</c>.
        /// </value>
        public bool IsReadOnly
        {
            get { return false; }
        }

        /// <summary>
        /// Gets the count.
        /// </summary>
        /// <value>The count.</value>
        public int Count
        {
            get { return this.collection.Count; }
        }

        /// <summary>
        /// Gets or sets the <see cref="T"/> at the specified index.
        /// </summary>
        /// <value>Value to insert.</value>
        public T this[int index]
        {
            get
            {
                return this.collection[index];
            }

            set
            {
                this.collection[index] = value;
            }
        }

        /// <summary>
        /// Gets the enumerator.
        /// </summary>
        /// <returns>Enumerate collection</returns>
        IEnumerator<T> IEnumerable<T>.GetEnumerator()
        {
            return this.collection.GetEnumerator();
        }

        /// <summary>
        /// Returns an enumerator that iterates through a collection.
        /// </summary>
        /// <returns>
        /// An <see cref="T:System.Collections.IEnumerator"/> object that can be used to iterate through the collection.
        /// </returns>
        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.collection.GetEnumerator();
        }

        /// <summary>
        /// Return index of item.
        /// </summary>
        /// <param name="item">The item which index will be return.</param>
        /// <returns>Index of item.</returns>
        public int IndexOf(T item)
        {
            return this.collection.IndexOf(item);
        }

        /// <summary>
        /// Inserts item at the specified index.
        /// </summary>
        /// <param name="index">The index at which will be item insert.</param>
        /// <param name="item">The item to insert.</param>
        public void Insert(int index, T item)
        {
            this.collection.Insert(index, item);
        }

        /// <summary>
        /// Removes at.
        /// </summary>
        /// <param name="index">The index of remove item.</param>
        public void RemoveAt(int index)
        {
            this.collection.RemoveAt(index);
        }

        /// <summary>
        /// Adds the specified item.
        /// </summary>
        /// <param name="item">The item to add.</param>
        public void Add(T item)
        {
            this.collection.Add(item);
        }

        /// <summary>
        /// Adds the range of items.
        /// </summary>
        /// <param name="collection">The collection.</param>
        public void AddRange(IList<T> collection)
        {
            this.collection.AddRange(collection);
        }

        /// <summary>
        /// Clears this instance.
        /// </summary>
        public void Clear()
        {
            this.collection.Clear();
        }

        /// <summary>
        /// Determines whether [contains] [the specified item].
        /// </summary>
        /// <param name="item">The item which containing in collection will checked.</param>
        /// <returns>
        ///    <c>true</c> if [contains] [the specified item]; otherwise, <c>false</c>.
        /// </returns>
        public bool Contains(T item)
        {
            return this.collection.Contains(item);
        }

        /// <summary>
        /// Copies array to specific index.
        /// </summary>
        /// <param name="array">The array to copy.</param>
        /// <param name="arrayIndex">Index of the array.</param>
        public void CopyTo(T[] array, int arrayIndex)
        {
            this.collection.CopyTo(array, arrayIndex);
        }

        /// <summary>
        /// Removes the specified item.
        /// </summary>
        /// <param name="item">The item to remove.</param>
        /// <returns><c>true</c> if remove otherwise <c>false</c></returns>
        public bool Remove(T item)
        {
            return this.collection.Remove(item);
        }
    }
}
